package com.aigc.sclassroom.mapper;

import com.aigc.sclassroom.pojo.SysUser;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface UserMapper {
    @Select("select u.user_id,dept_id,user_name,nick_name,email,phonenumber,sex,avatar,password,u.status,u.del_flag,role_name\n" +
            "from sys_user u\n" +
            "left join sys_user_role ur on u.user_id=ur.user_id\n" +
            "left join sys_role r on ur.role_id=r.role_id\n" +
            "where user_name=#{userName}")
    SysUser findByUserName(String username);

    @Insert("insert into sys_user(user_name,nick_name,password,create_time,update_time)"+"" +
            "values (#{userName},#{userName},#{encodePassword},now(),now())")
    void add(String userName, String encodePassword);

    @Insert("insert into sys_user_role(user_id,role_id)"+
            "values (#{userId},#{roleId})")
    void addUserRole(Long userId,Long roleId);

    @Select("select user_Name from sys_user where user_id=#{userId}")
    SysUser getUserNameById(Long userId);
}
